<template>
    <SearchTablePage :search-config="baseTableSearchModel" :table-config="baseTableModel" />
</template>

<script lang="tsx" setup>
import { ref, onActivated } from 'vue';
import { useRouter } from 'vue-router';
import dayjs from 'dayjs'; // 引入 dayjs
import { useEnumList } from '~/src/utils/useEnumList';
import StaffDailyCheckApi from '/@/api/webPath/StaffDailyCheckApi.ts';
import FORM_FIELD_TYPE from '/@/constants/FormFieldType';
import VDialog from '/@/utils/dialogUtil.ts';
import CommonStatusTag from '/@/components/CommonStatusTag.vue'; // 假设这是你的状态标签组件
// import { useTemplateName } from '~/src/utils/useTemplateName';
defineOptions({
    name: 'StaffDailyCheckPageData',
    title: '表格页',
});

const router = useRouter();
const baseTable = ref(null as any);
const baseTableSearch = ref(null as any);
const editRef = ref<any>(null);
const staffStatusEnumList = useEnumList("AttendanceSituation");
// const exportXlsName = useTemplateName(" ")
const baseTableSearchModel = ref({
    columnCount: 4,
    expandLimit: 6,
    autoFit: true,
    columnWidth: '320px',
    labelPosition: 'right',
    labelWidth: '100px',
    items: [
        {
            label: "晨检日期",
            field: "checkDate",
            clearable: true,
            type: FORM_FIELD_TYPE.DATE_RANGE,
            // fieldFormat: "date",
            placeholder: "请输入",
            rule: {
                trigger: 'blur',
                validator: (rule: any, value: any, callback: any) => {  //绑定验证
                    callback();
                },
            },

            config: {
                props: {   //日期精度配置
                    type: "daterange",
                    startPlaceholder: "开始日期",
                    endPlaceholder: "结束日期",
                    format: "YYYY-MM-DD",
                }
            },
        },
        {
            label: "人员名称",
            field: "staffName",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,
            placeholder: "请输入",
        },
        {
            label: "考勤状态",
            field: "staffStatus",
            clearable: true,
            type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
            options: staffStatusEnumList,
            placeholder: "请选择",
        },
        // {
        //     label: "是否发烧",
        //     field: "isFever",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
        //     options: [
        //         { value: '0', label: "否" },
        //         { value: '1', label: "是" },
        //     ],
        //     placeholder: "请选择",
        // },
        // {
        //     label: "是否腹泻",
        //     field: "isDiarrhea",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
        //     options: [
        //         { value: '0', label: "否" },
        //         { value: '1', label: "是" },
        //     ],
        //     placeholder: "请选择",
        // },
        // {
        //     label: "是否呕吐",
        //     field: "isVomiting",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
        //     options: [
        //         { value: '0', label: "否" },
        //         { value: '1', label: "是" },
        //     ],
        //     placeholder: "请选择",
        // },
        // {
        //     label: "是否外伤",
        //     field: "isTrauma",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
        //     options: [
        //         { value: '0', label: "否" },
        //         { value: '1', label: "是" },
        //     ],
        //     placeholder: "请选择",
        // },
        // {
        //     label: "是否皮肤化脓",
        //     field: "isSuppuration",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
        //     options: [
        //         { value: '0', label: "否" },
        //         { value: '1', label: "是" },
        //     ],
        //     placeholder: "请选择",
        // },
        // {
        //     label: "是否咳嗽流感",
        //     field: "isFlu",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
        //     options: [
        //         { value: '0', label: "否" },
        //         { value: '1', label: "是" },
        //     ],
        //     placeholder: "请选择",
        // },
        // {
        //     label: "是否咽喉肿痛",
        //     field: "isSoreThroat",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
        //     options: [
        //         { value: '0', label: "否" },
        //         { value: '1', label: "是" },
        //     ],
        //     placeholder: "请选择",
        // },
        // {
        //     label: "异常处理",
        //     field: "exceptionHand",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.INPUT,
        //     placeholder: "请输入",
        // },
        // {
        //     label: "创建时间",
        //     field: "create_time",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.DATE_RANGE,
        //     placeholder: "请选择日期范围",
        //     config: {
        //         props: {
        //             type: "daterange",
        //             startPlaceholder: "开始日期",
        //             endPlaceholder: "结束日期",
        //             format: "YYYY-MM-DD",
        //             // valueFormat: "YYYY-MM-DD",
        //         },
        //     },
        // },
    ],
    buttons: [
        {
            name: "导出",
            buttonClass: 'primary',
            width: 100,
            click: ({ row, handlers }) => {   //暴露的方法钩子
                StaffDailyCheckApi.pageDataXls(handlers.getRequestParams(), handlers.getXlsTitle())
            }
        },
        // {
        //     name: "新增",
        //     buttonClass: 'primary',
        //     width: 100,
        //     click: ({ row, handlers }) => {
        //         VDialog.open({
        //             title: '新增',
        //             content: {
        //                 type: 'component',
        //                 name: '/staffDailyCheck/edit',
        //                 query: {},
        //             },
        //             callBack: (data: any) => {
        //                 handlers.refresh();
        //             },
        //             onClose: () => {
        //                 console.log("对话框已关闭");
        //             },
        //         });
        //     },
        // },
        // {
        //     name: "批量删除",
        //     buttonClass: 'danger',
        //     width: 100,
        //     isShow: (row: any) => false,
        //     click: () => {
        //         console.log(baseTable.value.getSelection());
        //     },
        // },
    ],
});

const baseTableModel = ref({
    border: true,
    pagination: true,
    inline: true,
    selectable: true,
    isFullscreen: false,
    tooltip: true,
    minWidth: '200px',
    data: {
        current: 1,
        size: 10,
        total: 100,
        data: [],
    },
    requestData: { api: StaffDailyCheckApi.getPageData, query: {} },
    columns: [
        {
            label: "晨检日期",
            field: "checkDate",
            fieldFormat: "date",
            width: 200,
            config: {
                props: {   //日期精度配置
                    type: "daterange",
                    startPlaceholder: "开始日期",
                    endPlaceholder: "结束日期",
                    format: "YYYY-MM-DD",
                }
            },
        },
        {
            label: "人员名称",
            field: "staffName",
            width: 180,
        },
        {
            label: "确认状态",
            field: "confirmStatusTxt",
            render({ row }) {
                return <CommonStatusTag value={row["confirmStatus"]} valueMap={[
                    { value: '1', label: "已确认", type: "success" },
                    { value: '0', label: "未确认", type: "danger" },
                ]} />;
            },
            width: 180,
            // noExported: true
        },
        {
            label: "考勤状态",
            field: "staffStatus",
            render({ row }) {
                return <CommonStatusTag value={row["staffStatus"]} valueMap={[
                    { value: '1', label: "正常", type: "success" },
                    { value: "2", label: "请假", type: "info" },
                ]} />;
            },
            width: 180,
        },
        {
            label: "是否发烧",
            field: "isFever",
            render({ row }) {
                return <CommonStatusTag value={row["isFever"]} valueMap={[
                    { value: '0', label: "否", type: "success" },
                    { value: '1', label: "是", type: "danger" },
                ]} />;
            },
            width: 180,
        },
        {
            label: "是否腹泻",
            field: "isDiarrhea",
            render({ row }) {
                return <CommonStatusTag value={row["isDiarrhea"]} valueMap={[
                    { value: '0', label: "否", type: "success" },
                    { value: '1', label: "是", type: "danger" },
                ]} />;
            },
            width: 180,
        },
        {
            label: "是否呕吐",
            field: "isVomiting",
            render({ row }) {
                return <CommonStatusTag value={row["isVomiting"]} valueMap={[
                    { value: '0', label: "否", type: "success" },
                    { value: '1', label: "是", type: "danger" },
                ]} />;
            },
            width: 180,
        },
        {
            label: "是否外伤",
            field: "isTrauma",
            render({ row }) {
                return <CommonStatusTag value={row["isTrauma"]} valueMap={[
                    { value: '0', label: "否", type: "success" },
                    { value: '1', label: "是", type: "danger" },
                ]} />;
            },
            width: 180,
        },
        {
            label: "是否皮肤化脓",
            field: "isSuppuration",
            render({ row }) {
                return <CommonStatusTag value={row["isSuppuration"]} valueMap={[
                    { value: '0', label: "否", type: "success" },
                    { value: '1', label: "是", type: "danger" },
                ]} />;
            },
            width: 180,
        },
        {
            label: "是否咳嗽流感",
            field: "isFlu",
            render({ row }) {
                return <CommonStatusTag value={row["isFlu"]} valueMap={[
                    { value: '0', label: "否", type: "success" },
                    { value: '1', label: "是", type: "danger" },
                ]} />;
            },
            width: 180,
        },
        {
            label: "是否咽喉肿痛",
            field: "isSoreThroat",
            render({ row }) {
                return <CommonStatusTag value={row["isSoreThroat"]} valueMap={[
                    { value: '0', label: "否", type: "success" },
                    { value: '1', label: "是", type: "danger" },
                ]} />;
            },
            width: 180,
        },

        {
            label: "异常处理",
            field: "exceptionHand",
            width: 180,
        },
        {
            label: "创建时间",
            field: "create_time",
            width: 200,
        },
        {
            label: "更新时间",
            field: "update_time",
            width: 200,
        },
    ],
    actions: [
        {
            name: "详情",
            buttonClass: 'primary',
            buttonType: 'text',
            click: ({ row, index, handlers }) => {
                VDialog.open({
                    title: '详情',
                    content: {
                        type: 'component',
                        name: '/staffDailyCheck/detail',
                        query: { staffDailyCheckId: row.id },
                    },
                    callBack: (data: any) => {
                        handlers.refresh();
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });
            },
            isShow: (row: object) => true,
            fixed: 'right',
        },
        {
            name: "编辑",
            buttonClass: 'primary',
            buttonType: 'text',
            isShow: (row: object) => true,
            click: ({ row, index, handlers }) => {
                VDialog.open({
                    title: '编辑',
                    content: {
                        type: 'component',
                        name: '/staffDailyCheck/edit',
                        query: { staffDailyCheckId: row.id },
                    },
                    callBack: (data: any) => {
                        handlers.refresh();
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });
            },
            fixed: 'right',
        },
        // {
        //     name: "删除",
        //     buttonClass: 'danger',
        //     buttonType: 'text',
        //     fixed: 'right',
        //     click: ({ row, index, handlers }) => {
        //         $baseConfirm('您确定要删除当前项吗', null, async () => {
        //             const { message } = await StaffDailyCheckApi.del({ staffDailyCheckIds: row.id });
        //             $baseMessage(message, 'success', 'vab-hey-message-success');
        //             handlers.refresh();
        //         });
        //     },
        // },
    ],
});

onActivated(() => {
});
</script>
